<template>
<el-card class="box-card">
	<div slot="header" class="clearfix">
	<span>检定提醒 </span>
	<el-button style="float: right; padding: 3px 0" type="text" ></el-button>
	</div>
  <div >

    <el-table v-loading="loading" :data="checkList">
      <el-table-column label="状态" align="center" >
         <template slot-scope="scope">
           <i class="el-icon-message-solid" style="font-size: 30px;color: rgb(235, 98, 59);" @click="handleRead(scope.row)"></i>
         </template>
      </el-table-column>
 <el-table-column label="单位名称" align="center" prop="zyxDevice.unitname" />
       <el-table-column label="设备类别" align="center" prop="zyxDevice.devicetype" />
      <el-table-column label="设备型号" align="center" prop="zyxDevice.devicemodel" />
      <el-table-column label="检定周期" align="center" prop="zyxCheck.warncycle" />
      <el-table-column label="上次检定时间" align="center" prop="lastdate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zyxCheck.lastdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下次检定时间" align="center" prop="nextcheckdate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zyxCheck.nextcheckdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
       <el-table-column label="距离时间" align="center" prop="zyxCheck.distanceday" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
   </el-card>
</template>

<script>
import { listMyCheck, getCheck, delCheck, addCheck, updateCheck, exportCheck } from "@/api/zyx/check";

import { listWarn,updMyWarnRead} from "@/api/zyx/warn";

export default {
  name: "Check",
  components: {
  },
  data() {
    return {
      devicetypeOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检定基础信息表格数据
      checkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 起始日期时间范围
      daterangeStartdate: [],
      // 下次日期时间范围
      daterangeNextdate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 6,
        deviceid: null,
        startdate: null,
        devicemodel:null,
        warntype:null,
        orderByColumn:'create_time',
        isAsc:'desc',
        isread:'N',
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("zyx_devicetype").then(response => {
      this.devicetypeOptions = response.data;
    });
  },
  methods: {
    handleRead(row){
      updMyWarnRead(row.id).then(response => {
        this.getList();
      });
    },
    formatDate  (value) {
      let date = new Date(value);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? ('0' + MM) : MM;
      let d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      let h = date.getHours();
      h = h < 10 ? ('0' + h) : h;
      let m = date.getMinutes();
      m = m < 10 ? ('0' + m) : m;
      let s = date.getSeconds();
      s = s < 10 ? ('0' + s) : s;
      return y + '-' + MM + '-'  + d + '-'  + h + ':'  + m + ':'  + s;
    },
    //提醒周期变化计算提醒日期
    changeInput() {
      // console.log(new Date(this.form.startdate).getDate())
        let date1 =new Date(this.form.startdate)
        //  // let dateTemp = date1.setDate(date1.getDate() + this.form.warncycle )
         let dateTemp = date1.setDate(date1.getDate() + parseInt(this.form.warncycle)-parseInt(this.form.warndaynum) )
         // console.log(dateTemp)
         this.form.nextdate=this.formatDate(dateTemp)
        },
    // 设备类别字典字典翻译
    devicetypeFormat(row, column) {
      return this.selectDictLabel(this.devicetypeOptions, row.zyxDevice.devicetype);
    },
    /** 查询检定基础信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      this.queryParams.warntype="2";
      listWarn(this.queryParams).then(response => {
        this.checkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departid: null,
        deviceid: null,
        startdate: null,
        nextdate: null,
        warncycle: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        lastdate:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeStartdate = [];
      this.daterangeNextdate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },


  }
};
</script>
